package com.twu.biblioteca.app.book;

import com.twu.biblioteca.app.user.User;

public class CheckoutDetails implements Comparable<CheckoutDetails> {
    User checkedOutBy;
    CheckoutStatus checkoutStatus;

    public CheckoutDetails() {
        this.checkedOutBy = null;
        this.checkoutStatus = CheckoutStatus.AVAILABLE;
    }

    public CheckoutDetails(User user, CheckoutStatus checkoutStatus) {
        this.checkedOutBy = user;
        this.checkoutStatus = checkoutStatus;
    }

    public User getCheckedOutBy() {
        return checkedOutBy;
    }

    public void setCheckedOutBy(User checkedOutBy) {
        this.checkedOutBy = checkedOutBy;
    }

    public CheckoutStatus getCheckoutStatus() {
        return checkoutStatus;
    }

    public void setCheckoutStatus(CheckoutStatus checkoutStatus) {
        this.checkoutStatus = checkoutStatus;
    }

    @Override
    public int compareTo(CheckoutDetails other){
        int compareTitle = this.checkoutStatus.compareTo(other.checkoutStatus);
        return compareTitle == 0 ? this.checkedOutBy.compareTo(other.checkedOutBy) : compareTitle;
    }

    @Override
    public boolean equals(Object otherObj) {
        if (otherObj == null) {
            return false;
        }
        if (getClass() != otherObj.getClass()) {
            return false;
        }

        CheckoutDetails otherCheckoutDetails  = (CheckoutDetails) otherObj;
        if (this.checkoutStatus == otherCheckoutDetails.checkoutStatus) {
            return this.checkedOutBy == otherCheckoutDetails.checkedOutBy;
        }
        return false;
    }
}
